<template lang="html">
    <div class="message">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;英文用户协议和隐私政策</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div style="height:20px;"></div>
            <el-form label-width="150px" class="demo-ruleForm">
                <el-form-item label="用户协议和隐私政策(英文)：">
                    <div class="news-editor">
                        <ueditor ref="contentEn" @load="editorLoadCN" :width="editor_style.width" :height="editor_style.height" id="editor"></ueditor>
                    </div>
                    <div style="color:red;padding-left:10px;">*请输入英文 </div>
                </el-form-item >
                <el-form-item>
                    <el-button type="primary" @click="submit()">保存</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import {getUserEN,postUserEN} from '@/api/configuration/list'
import editor from '../../components/common/editor.vue'
import ueditor from '../../components/common/ueditor.vue'

    export default {
        name: "configcn",
        components:{
            editor,
            ueditor,
        },
        data() {
            return {
                contentEn:'',//中文协议
                editor_style: {
                    width: 'auto',
                    height: 'auto'
                },
            }
        },
        created(){
            //获取中文用户协议
            this.getUserEN();
        },
        mounted() {
            
        },
        methods: {
            //获取
            getUserEN(){
                getUserEN().then(res => {
                    this.contentEn = res.data;
                    //把获取的内容显示在富文本编辑器里
                    this.$refs.contentEn.setHtml(this.contentEn)
                })
            },
            //提交
            submit(){
                //获取富文本编辑器里的内容
                this.contentEn = this.$refs.contentEn.getHtml();
                if(this.contentEn == ''){
                    this.$message({
                        message: '请输入英文内容！',
                        type: 'warning'
                    });
                    return false;
                }
                postUserEN(this.contentEn).then(res => {
                    if(res.code == 200){
                        this.$message({
                            message: '保存成功！',
                            type: 'success'
                        });
                        this.getUserEN();//重新加载
                    }else {
                        this.$message.error('保存失败！');
                    }
                })
            },
            editorLoadCN(originalName, resultText) {
                // originalName 上传文件名，resultText 服务器端返回的text
                this.$refs.contentEn.insertImg(resultText)
            },
        }
    }
</script>

<style lang="css" scoped>
.del {
    color: #f00;
}
</style>
